package com.self.study.subjectsstudy.common;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import lombok.Getter;

/**
 * api接口返回
 * <p>
 * Created on 2018/7/13
 *
 * @author Saligia
 */
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
@Getter
public class ResultInfo {

    private int code;
    private String message;
    private Object result;

    public ResultInfo(Status status) {
        this.code = status.code;
        this.message = status.message;
    }

    public ResultInfo message(String message) {
        this.message = message;
        return this;
    }

    public ResultInfo result(Object result) {
        this.result = result;
        return this;
    }

    @Getter
    public enum Status {

        // 公共部分
        SUCCESS(0, "请求成功"),
        REPEAT_LOGIN(1001,"您已登录，不可重复登录！如需切换账号，请先退出登录再重新登录！"),
        REQUEST_PARAMETER_ERROR(1002, "请求参数错误"),
        SIGN_ERROR(1003, "sign验证错误"),
        LOGOUT(1004, "已退出登录"),
        RESOURCE_NOT_FOUND(1005, "没有找到资源"),
        FAILURE(1006, "操作执行失败"),
        UNAUTHORITY(1007, "无访问权限"),
        NO_DATA(1008, "没有查询到数据"),
        MESSAGE_ERROR(1009, "短信发送异常"),


        SYSTEM_ERROR(1098, "系统异常"),
        UNKNOWN_ERROR(1099, "未知异常"),
        ERROR_400(1400, "请求参数值不符合要求"),
        ERROR_403(1403, "非法请求"),
        ERROR_404(1404, "访问的路径不存在"),

        // 用户
        USER_EXISTS(2001, "账户已存在"),
        LOGIN_FAIL(2002, "用户名/密码错误"),
        USER_NOT_EXISTS(2003, "用户不存在"),
        USER_LOCKED(2004, "用户被锁定"),
        CODE_LOSE(2005, "缺少验证码"),
        CODE_ERROR(2007, "验证码错误"),
        RESTRICT(2006, "登录受限制");


        private int code;
        private String message;

        Status(int code, String message) {
            this.code = code;
            this.message = message;
        }
    }

}
